from django.db import models
from datetime import datetime
from business.models import GoodsModel,BusUserModel

# Create your models here.


class CusUserModel(models.Model):
    c_name = models.CharField('用户名',max_length=64,default='')
    password = models.CharField('密码',max_length=256,default='')
    nickname = models.CharField('昵称',max_length=64,default='')
    portrait = models.CharField('头像',max_length=256,default='')
    gender = models.CharField('性别',max_length=16,default='')
    mobile = models.CharField('手机号',max_length=16,default='')
    member = models.IntegerField('会员级别 （0普通 1贵尊 2超级）',default=0)
    freeze = models.IntegerField('是否冻结（1冻结 2不冻结）', default=2)
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.c_name

    class Meta:
        db_table = 'cus_user'
        verbose_name_plural = '顾客模型类'


# 收货地址
class AddressModel(models.Model):
    user = models.ForeignKey(to=CusUserModel,on_delete=models.CASCADE,verbose_name='所属用户')
    province = models.CharField('省',max_length=256,default='')
    city = models.CharField('市',max_length=256,default='')
    county = models.CharField('县，区',max_length=256,default='')
    detail = models.CharField('详细地址',max_length=256,default='')
    name = models.CharField('收货人姓名',max_length=64,default='')
    mobile = models.CharField('收货人电话',max_length=16,default='')
    default = models.BooleanField('是否默认 0否 1是',default=0)
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'addr'
        verbose_name_plural = '地址模型类'


# 收藏
class CollectModel(models.Model):
    user = models.ForeignKey(to=CusUserModel,on_delete=models.CASCADE,verbose_name='所属用户')
    good = models.ForeignKey(to=GoodsModel, on_delete=models.CASCADE, verbose_name='所属商品')
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.user.c_name

    class Meta:
        db_table = 'collect'
        verbose_name_plural = '收藏模型类'


# vip类型表
class VipListModel(models.Model):
    name = models.CharField(max_length=56,verbose_name="VIP名字")
    price = models.CharField(max_length=16,default=0,verbose_name="价格")
    time_text = models.CharField(max_length=124,default="",verbose_name="有效期")
    start_time = models.DateTimeField(default=datetime.now, verbose_name="开始时间")
    end_time = models.DateTimeField(default=datetime.now, verbose_name="结束时间")
    time = models.CharField(max_length=56,default=0,verbose_name="有效期（s）")

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'vip_list_model'


# 购买vip表
class PayVipModel(models.Model):
    vip_order_num = models.CharField(max_length=555,default="", verbose_name="订单号")
    uid = models.ForeignKey(to=CusUserModel,on_delete=models.CASCADE,verbose_name="用户id")
    vid = models.ForeignKey(to=VipListModel,on_delete=models.CASCADE,verbose_name="vip类型id")
    amount = models.CharField(max_length=16,verbose_name="支付金额")
    status = models.CharField(max_length=16,default=0, verbose_name="订单状态  0 待支付  1已支付  2 已取消")
    open_time = models.IntegerField( max_length=56,verbose_name="生效时间")
    end_time = models.IntegerField(max_length=56,verbose_name="结束时间")
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):

        return self.vip_order_num

    class Meta:
        db_table = 'pay_vip_model'


# 用户优惠卷表
class CouponModel(models.Model):
    uid = models.ForeignKey(to=CusUserModel,on_delete=models.CASCADE,verbose_name="优惠卷用户")
    name = models.CharField(max_length=56,verbose_name="优惠卷名")
    price = models.CharField(max_length=16,verbose_name="优惠卷金额")
    type = models.CharField(max_length=56,verbose_name="优惠卷类型")
    start_time = models.DateTimeField(default=datetime.now, verbose_name="开始时间")
    end_time = models.DateTimeField(default=datetime.now, verbose_name="结束时间")
    time = models.CharField(max_length=56, default=0, verbose_name="有效期（s）")

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'coupon_model'


# 用户订单表
class PayOrderModel(models.Model):
    order_num = models.CharField(max_length=56, default="",verbose_name='订单号')
    uid = models.ForeignKey(to=CusUserModel, on_delete=models.CASCADE,verbose_name="用户id")
    bid = models.ForeignKey(to=BusUserModel,on_delete=models.CASCADE,verbose_name="订单商家id")
    fid = models.ForeignKey(to=GoodsModel,on_delete=models.CASCADE,verbose_name="菜品id")
    amount = models.CharField(max_length=16, default=0, verbose_name="支付金额")
    status = models.CharField(max_length=16, default=0,verbose_name="订单状态  0 待支付  1已支付 2已完成 3已取消")
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.order_num

    class Meta:
        db_table = 'pay_order_model'


# 用户对商家评论表
class CommentModel(models.Model):
    user_id = models.ForeignKey(to=CusUserModel,on_delete=models.CASCADE,verbose_name="用户id")
    good_id = models.ForeignKey(to=GoodsModel,on_delete=models.CASCADE,verbose_name="菜品id")
    context = models.CharField(max_length=256, default="",verbose_name="评论内容")
    parent_id = models.IntegerField(default=0,verbose_name="回复的评论ID")
    root_id = models.IntegerField(default=0,verbose_name="回复的评论根ID")
    establish_time = models.DateTimeField('创建时间', default=datetime.now())
    change_time = models.DateTimeField('更改时间', default=datetime.now())
    delete = models.BooleanField('是否删除 0否 1是', default=0)

    def __str__(self):
        return self.context

    class Meta:
        db_table = 'comment_model'




